﻿#region

using System;
using System.Windows;
using Minion.Win.Client.Constants;
using Minion.Win.Client.Helper;
using Minion.Win.Client.Models;
using RestSharp;

#endregion

namespace Minion.Win.Client.Service.Concrete
{
    public class NotificationService : INotificationService
    {
        public bool SendNotification(Guid locationItemDetailId, string message)
        {
            //Find the locationitemdeatail object
            var locItemDetail = Utilities.FindObject<LocationItemDetail>(App.CurrentLocationDetails,
                                                                         locationItemDetailId);
            var emailTo = locItemDetail.Email;

            var restClient = new RestClient(AppSettings.ApiUrlSetting);
            var request = new RestRequest(ApiUrl.SendEmal, Method.POST);
            request.AddParameter("to", emailTo);
            request.AddParameter("message", message);

            try
            {
                restClient.ExecuteAsync(request, response => MessageBox.Show("Email successfully sent", "Notification", MessageBoxButton.OK));
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}